package net.exoweb.animate.graphics
{
    import flash.events.*;

    import net.exoweb.animate.common.Maths;
    import net.exoweb.animate.graphics.GBeam;
    import net.exoweb.animate.graphics.GShape;

    public class GNuclear extends GShape
    {
        private var beam:GBeam;

        public function GNuclear(color:uint=0xFFA000, bm:String="normal")
        {
            super(color, bm);
            beam = new GBeam(40, 40);
            beam.display();
            beam.visible = false;
            beam.rotation = 45;
            addChild(beam);
            addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        }

        public function light(e:Event):void
        {
            if(beam.x > 30)
            {
                beam.visible = false;
                removeEventListener(Event.ENTER_FRAME, light);
                addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
            }
            else
            {
                beam.x += 2;
                beam.y += 2;
            }
        }

        public function mouseOver(e:Event):void
        {
            beam.visible = true;
            beam.x = -20;
            beam.y = -20;
            removeEventListener(MouseEvent.MOUSE_OVER, mouseOver);
            addEventListener(Event.ENTER_FRAME, light);
        }

        override public function display():void
        {
            graphics.clear();
            graphics.lineStyle(2, color);
            graphics.beginFill(0);
            graphics.drawCircle(0, 0, 20);
            graphics.endFill();

            graphics.lineStyle(0);
            graphics.beginFill(color);
            graphics.drawCircle(0, 0, 4);
            graphics.endFill();

            var r:Number = 17;
            var dr:Number = 6;
            var q:Number = Maths.getRadian(60);
            var dx:Number = r * Math.cos(q);
            var dy:Number = r * Math.sin(q);

            graphics.beginFill(color);
            graphics.moveTo(dx, dy);
            for(var i:int=60; i<=120; i++)
            {
                q = Maths.getRadian(i);
                dx = r * Math.cos(q);
                dy = r * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            for(i=120; i>=60; i--)
            {
                q = Maths.getRadian(i);
                dx = dr * Math.cos(q);
                dy = dr * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            graphics.endFill();

            q = Maths.getRadian(180);
            dx = r * Math.cos(q);
            dy = r * Math.sin(q);
            graphics.beginFill(color);
            graphics.moveTo(dx, dy);
            for(i=180; i<=240; i++)
            {
                q = Maths.getRadian(i);
                dx = r * Math.cos(q);
                dy = r * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            for(i=240; i>=180; i--)
            {
                q = Maths.getRadian(i);
                dx = dr * Math.cos(q);
                dy = dr * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            graphics.endFill();

            q = Maths.getRadian(300);
            dx = r * Math.cos(q);
            dy = r * Math.sin(q);
            graphics.beginFill(color);
            graphics.moveTo(dx, dy);
            for(i=300; i<=360; i++)
            {
                q = Maths.getRadian(i);
                dx = r * Math.cos(q);
                dy = r * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            for(i=360; i>=300; i--)
            {
                q = Maths.getRadian(i);
                dx = dr * Math.cos(q);
                dy = dr * Math.sin(q);
                graphics.lineTo(dx, dy);
            }
            graphics.endFill();
        }
    }
}
